//
//  HSYStepBaseViewController.m
//  Report-JKM
//
//  Created by 陈浩 on 2017/4/24.
//  Copyright © 2017年 金开门. All rights reserved.
//

#import "HSYStepBaseViewController.h"
#import "BDGetShopInfoRequest.h"

@interface HSYStepBaseViewController ()

@end

@implementation HSYStepBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    __weak typeof(self)weakSelf = self;
    [self shopInfoWithModel:self.model complete:^(BDUserShopModel *model) {
        [weakSelf fillbackIfNeed];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)fillbackIfNeed{
    
}

-(void)shopInfoWithModel:(BDBusinessModel *)model complete:(void(^)(BDUserShopModel *model)) complete{
    
    if (!self.model){
        complete(nil);
        return;
    }
    
    if (self.userShopModel) {
        complete(self.userShopModel);
        return;
    }
    
    __weak typeof(self)weakSelf = self;

    NSString *uid = [NSString stringWithFormat:@"%ld",(long)model.uid];
    BDGetShopInfoRequest *task = [[BDGetShopInfoRequest alloc] init];
    task.uid = uid;
    
    [BDNetworkManager POST:task completionHander:^(id responseObject, NSString *resultString) {
        if (responseObject) {
            BDUserShopModel *model = [BDUserShopModel mj_objectWithKeyValues:responseObject];
            weakSelf.userShopModel = model;
            if (complete) {
                complete(model);
            }
        }else{
            if (resultString) {
                [weakSelf showMessage:resultString];
            }
        }
    }];
}

- (void)handleNext{
    if (self.readOnly) {
        BDBusinessModel *business = [BDBusinessModel mj_objectWithKeyValues:[self.model mj_keyValues]];
        business.auStep = [NSString stringWithFormat:@"%ld", [business.auStep integerValue]+1];
        [self nextStepWihBusinessModel:business  userShopModel:self.userShopModel readOnly:self.readOnly];
        
    }else{
        [self commitData];
    }
    
}

- (void)commitData{}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    return !self.readOnly;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
